const express =require('express')
const router = express.Router()
const c =require('../connection')
//1.职位列表
router.get('/list',(req,res,next)=>{
	var sql='select jid, title , ctime from ht_job order by ctime desc limit ?,?;select count(*) as n from ht_job'
	var obj=req.query
	if(!obj.pno){
		obj.pno=1
	}
	if(!obj.count){
		obj.count=5
	}
	var start= (obj.pno-1)*obj.count
	var size = parseInt(obj.count)
	c.query(sql,[start,size],(err,r)=>{
		if(err){
			return next(err)
		}console.log(r)
		res.send({
			code:200,
			msg:'职位列表',
			data:r[0],
			total:r[1][0].n,
			pno:obj.pno
		})
	})
})


//2.职位详情
router.get('/detail',(req,res,next)=>{
	var sql = 'select detail from ht_job where jid=?'
	var obj=req.query
	obj.jid=parseInt(obj.jid)
	c.query(sql,[obj.jid],(err,r)=>{
		if(err){
			return next(err)
		}
		if(r.length>0){
			res.send({
				code:200,
				msg:'职位详情',
				data:r
			})
		}else{
			res.send({
				code:400,
				msg:'职位不存在',
			})
		}
	})
})
module.exports = router